package demo.liu.one.configs.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author by Liujt
 * @Classname ConfirmCallbackConfig
 * @Description 未到达交换机回调，配置文件添加：spring.rabbitmq.publisher-confirm-type=CORRELATED
 * @Date 2021/6/23 9:48
 */
@Slf4j
@Component
public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback{

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (!ack) {
            log.error("消息发送异常!");
        } else {
            log.info("发送者爸爸已经收到确认，correlationData={} ,ack={}, cause={}", correlationData.getId(), ack, cause);
        }
    }
}
